package com.example.rabbitmqdemo.priority_queue;

import com.example.rabbitmqdemo.util.ConnectionUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.TimeoutException;

public class PriorityQueueTest {
    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();

        HashMap<String, Object> map = new HashMap<>();
        map.put("x-max-priority", 10);
        channel.queueDeclare("queue.priority", true,
                false, false, map);

        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
        builder.priority(5);
        AMQP.BasicProperties properties = builder.build();
        channel.exchangeDeclare("exchange_priority", "fanout", true);
        channel.queueBind("queue.priority", "exchange_priority", "");
        channel.basicPublish("exchange_priority", "rk_priority",
                properties, "message".getBytes());

        channel.close();
        connection.close();
    }
}
